﻿Namespace Global.Runa.UI.Threading

    Public Class DispatcherFrame
        Inherits DispatcherObject

        Private _continue As Boolean
        Private _exitWhenRequested As Boolean

        Public Sub New()
            Me.New(True)
        End Sub

        Public Sub New(ByVal exitWhenRequested As Boolean)
            Me._exitWhenRequested = exitWhenRequested
            Me._continue = True
        End Sub

        Public Property [Continue]() As Boolean
            Get
                Dim flag As Boolean = Me._continue
                If (Not flag OrElse Not Me._exitWhenRequested) Then
                    Return flag
                End If
                Dim dispatcher As Dispatcher = MyBase.Dispatcher
                Return ((Not dispatcher._exitAllFrames AndAlso Not dispatcher._hasShutdownStarted) AndAlso flag)
            End Get
            Set(ByVal value As Boolean)
                Me._continue = value
                MyBase.Dispatcher.BeginInvoke(DispatcherPriority.Send,
                    Function(unused As Object)
                        Return Nothing
                    End Function, Nothing)
            End Set
        End Property

    End Class

End Namespace